package com.dragon.mmochat.model.role;

import java.io.Serializable;

import com.dragon.mmochat.model.enumType.MmochatPropType;
import com.dragon.mmochat.service.MmochatMainService;

public class MmochatFriend implements Serializable, Comparable<MmochatFriend> {
	private static final long serialVersionUID = -4988906121371031406L;
	private int roleId;
	private int bmpId; // TODO: 好友列表头像
	private String name;
	private int friendValue = 0; // 好友度
	private int friendListPrority = 0; // TODO: 好友列表排序优先级,由聊天次数决定
	private String moodInfo = null; // TODO: 个性签名
	private String lastChat = null; // 最后一个聊天对话内容

	public int getRoleId() {
		return roleId;
	}

	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFriendValue() {
		return friendValue;
	}

	public void setFriendValue(int friendValue) {
		this.friendValue = friendValue;
	}

	public void addFriendValue(int add) {
		friendValue += add;
		friendValue = Math.max(0, friendValue);
		friendValue = Math.min(friendValue, 999999);
	}

	public int getFriendListPrority() {
		int extraPrority = 0;
		MmochatPlayer me = MmochatMainService.players.get(roleId);
		if (me != null) {
			// 在线的比离线的优先级高
			extraPrority += 0x1fffffff;
			if (me.hasPropEffect(MmochatPropType.会员周卡.getEffectKey())) {
				// 会员比非会员优先
				extraPrority += 0x1fffffff;
			}
		}
		return friendListPrority + extraPrority;
	}

	// 与终端10.1协议里定义要统一， 1:在线; 4:被我关注
	public int getFriendState(MmochatPlayer me) {
		int state = 0;
		if (isOnline()) {
			state += 1;
		}
		if (me.getMyIdols().containsKey(roleId)) {
			state += 4;
		}
		return state;
	}

	public void setFriendListPrority(int friendListPrority) {
		this.friendListPrority = friendListPrority;
	}

	public void addFriendListPrority() {
		friendListPrority++;
	}

	public int getBmpId() {
		return bmpId;
	}

	public void setBmpId(int bmpId) {
		this.bmpId = bmpId;
	}

	public String getMoodInfo() {
		return (moodInfo != null) ? moodInfo : "";
	}

	public void setMoodInfo(String moodInfo) {
		this.moodInfo = moodInfo;
	}

	public boolean isVip() {
		MmochatPlayer me = MmochatMainService.players.get(roleId);
		if (me != null) {
			if (me.hasPropEffect(MmochatPropType.会员周卡.getEffectKey())) {
				return true;
			}
		}
		return false;
	}

	private boolean isOnline() {
		MmochatPlayer me = MmochatMainService.players.get(roleId);
		if (me != null) {
			return true;
		}
		return false;
	}

	@Override
	public int compareTo(MmochatFriend arg0) {
		return arg0.getFriendValue() - friendValue;
	}

	public String getLastChat() {
		return lastChat;
	}

	public void setLastChat(String lastChat) {
		this.lastChat = lastChat;
	}

}
